package com.fancy.learncenter.view;

import android.content.Context;
import android.graphics.Typeface;
import android.view.ViewGroup;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.lib.WheelView;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.view.WheelOptions;

/**
 * Created by hyy on 2018/2/25.
 * Explain activity as
 */

public class CustomOptionsPickerView extends OptionsPickerView {
    public CustomOptionsPickerView(Builder builder) {
        super(builder);
    }

    @Override
    public void dismiss() {
        super.dismiss();

        if (cancleCallBack != null) {
            cancleCallBack.cancleCallBack();
        }
    }

    private CancleCallBack cancleCallBack;

    public void setCancleCallBack(CancleCallBack cancleCallBack) {
        this.cancleCallBack = cancleCallBack;
    }

    public interface CancleCallBack {
        void cancleCallBack();
    }


    //建造器
    public static class Builder extends OptionsPickerView.Builder {
        private int layoutRes = com.bigkoo.pickerview.R.layout.pickerview_options;
        private CustomListener customListener;
        private Context context;
        private OnOptionsSelectListener optionsSelectListener;

        private String Str_Submit;//确定按钮文字
        private String Str_Cancel;//取消按钮文字
        private String Str_Title;//标题文字

        private int Color_Submit;//确定按钮颜色
        private int Color_Cancel;//取消按钮颜色
        private int Color_Title;//标题颜色

        private int Color_Background_Wheel;//滚轮背景颜色
        private int Color_Background_Title;//标题背景颜色

        private int Size_Submit_Cancel = 17;//确定取消按钮大小
        private int Size_Title = 18;//标题文字大小
        private int Size_Content = 18;//内容文字大小

        private boolean cancelable = true;//是否能取消
        private boolean linkage = true;//是否联动
        private boolean isCenterLabel = true;//是否只显示中间的label

        private int textColorOut; //分割线以外的文字颜色
        private int textColorCenter; //分割线之间的文字颜色
        private int dividerColor; //分割线的颜色
        private int backgroundId; //显示时的外部背景色颜色,默认是灰色
        public ViewGroup decorView;//显示pickerview的根View,默认是activity的根view
        // 条目间距倍数 默认1.6
        private float lineSpacingMultiplier = 1.6F;
        private boolean isDialog;//是否是对话框模式

        private String label1;
        private String label2;
        private String label3;

        private boolean cyclic1 = false;//是否循环，默认否
        private boolean cyclic2 = false;
        private boolean cyclic3 = false;

        private Typeface font;

        private int option1;//默认选中项
        private int option2;
        private int option3;

        private int xoffset_one;//x轴偏移量
        private int xoffset_two;
        private int xoffset_three;

        private WheelView.DividerType dividerType;//分隔线类型

        public Builder(Context context, OnOptionsSelectListener listener) {
            super(context, listener);
        }
//
//        //Required
//        public Builder(Context context, OnOptionsSelectListener listener) {
//            this.context = context;
//            this.optionsSelectListener = listener;
//        }

        //Option

        public CustomOptionsPickerView.Builder setSubmitText(String Str_Cancel) {
            this.Str_Submit = Str_Cancel;
            return this;
        }

        public CustomOptionsPickerView.Builder setCancelText(String Str_Cancel) {
            this.Str_Cancel = Str_Cancel;
            return this;
        }

        public CustomOptionsPickerView.Builder setTitleText(String Str_Title) {
            this.Str_Title = Str_Title;
            return this;
        }

        public CustomOptionsPickerView.Builder isDialog(boolean isDialog) {
            this.isDialog = isDialog;
            return this;
        }

        public CustomOptionsPickerView.Builder setSubmitColor(int Color_Submit) {
            this.Color_Submit = Color_Submit;
            return this;
        }

        public CustomOptionsPickerView.Builder setCancelColor(int Color_Cancel) {
            this.Color_Cancel = Color_Cancel;
            return this;
        }

        /**
         * 显示时的外部背景色颜色,默认是灰色
         *
         * @param backgroundId
         * @return
         */
        public CustomOptionsPickerView.Builder setBackgroundId(int backgroundId) {
            this.backgroundId = backgroundId;
            return this;
        }

        /**
         * 必须是viewgroup
         * 设置要将pickerview显示到的容器
         *
         * @param decorView
         * @return
         */
        public CustomOptionsPickerView.Builder setDecorView(ViewGroup decorView) {
            this.decorView = decorView;
            return this;
        }

        public CustomOptionsPickerView.Builder setLayoutRes(int res, CustomListener listener) {
            this.layoutRes = res;
            this.customListener = listener;
            return this;
        }

        public CustomOptionsPickerView.Builder setBgColor(int Color_Background_Wheel) {
            this.Color_Background_Wheel = Color_Background_Wheel;
            return this;
        }

        public CustomOptionsPickerView.Builder setTitleBgColor(int Color_Background_Title) {
            this.Color_Background_Title = Color_Background_Title;
            return this;
        }

        public CustomOptionsPickerView.Builder setTitleColor(int Color_Title) {
            this.Color_Title = Color_Title;
            return this;
        }

        public CustomOptionsPickerView.Builder setSubCalSize(int Size_Submit_Cancel) {
            this.Size_Submit_Cancel = Size_Submit_Cancel;
            return this;
        }

        public CustomOptionsPickerView.Builder setTitleSize(int Size_Title) {
            this.Size_Title = Size_Title;
            return this;
        }

        public CustomOptionsPickerView.Builder setContentTextSize(int Size_Content) {
            this.Size_Content = Size_Content;
            return this;
        }

        public CustomOptionsPickerView.Builder setOutSideCancelable(boolean cancelable) {
            this.cancelable = cancelable;
            return this;
        }

        /**
         * 此方法已废弃
         * 不联动的情况下，请调用 setNPicker 方法。
         */
        @Deprecated
        public CustomOptionsPickerView.Builder setLinkage(boolean linkage) {
            this.linkage = linkage;
            return this;
        }

        public CustomOptionsPickerView.Builder setLabels(String label1, String label2, String label3) {
            this.label1 = label1;
            this.label2 = label2;
            this.label3 = label3;
            return this;
        }

        /**
         * 设置间距倍数,但是只能在1.2-2.0f之间
         *
         * @param lineSpacingMultiplier
         */
        public CustomOptionsPickerView.Builder setLineSpacingMultiplier(float lineSpacingMultiplier) {
            this.lineSpacingMultiplier = lineSpacingMultiplier;
            return this;
        }

        /**
         * 设置分割线的颜色
         *
         * @param dividerColor
         */
        public CustomOptionsPickerView.Builder setDividerColor(int dividerColor) {
            this.dividerColor = dividerColor;
            return this;
        }

        /**
         * 设置分割线的类型
         *
         * @param dividerType
         */
        public CustomOptionsPickerView.Builder setDividerType(WheelView.DividerType dividerType) {
            this.dividerType = dividerType;
            return this;
        }

        /**
         * 设置分割线之间的文字的颜色
         *
         * @param textColorCenter
         */
        public CustomOptionsPickerView.Builder setTextColorCenter(int textColorCenter) {
            this.textColorCenter = textColorCenter;
            return this;
        }

        /**
         * 设置分割线以外文字的颜色
         *
         * @param textColorOut
         */
        public CustomOptionsPickerView.Builder setTextColorOut(int textColorOut) {
            this.textColorOut = textColorOut;
            return this;
        }

        public CustomOptionsPickerView.Builder setTypeface(Typeface font) {
            this.font = font;
            return this;
        }

        public CustomOptionsPickerView.Builder setCyclic(boolean cyclic1, boolean cyclic2, boolean cyclic3) {
            this.cyclic1 = cyclic1;
            this.cyclic2 = cyclic2;
            this.cyclic3 = cyclic3;
            return this;
        }

        public CustomOptionsPickerView.Builder setSelectOptions(int option1) {
            this.option1 = option1;
            return this;
        }

        public CustomOptionsPickerView.Builder setSelectOptions(int option1, int option2) {
            this.option1 = option1;
            this.option2 = option2;
            return this;
        }

        public CustomOptionsPickerView.Builder setSelectOptions(int option1, int option2, int option3) {
            this.option1 = option1;
            this.option2 = option2;
            this.option3 = option3;
            return this;
        }

        public CustomOptionsPickerView.Builder setTextXOffset(int xoffset_one, int xoffset_two, int xoffset_three) {
            this.xoffset_one = xoffset_one;
            this.xoffset_two = xoffset_two;
            this.xoffset_three = xoffset_three;
            return this;
        }

        public CustomOptionsPickerView.Builder isCenterLabel(boolean isCenterLabel) {
            this.isCenterLabel = isCenterLabel;
            return this;
        }

        public CustomOptionsPickerView build() {
            return new CustomOptionsPickerView(this);
        }
    }

}
